<?php
class Shop extends BaseBean{

    protected $_table= "tb_shop";
    protected $_primarykey= "id";
    protected $_table_alias= "a";
    protected $_mustFields =array("code"=>"编号","name"=>"名称");
    protected $_uniqueFields =array("a.code"=>"编号");


    public function generateSql(){
        return "select a.*,b.name as company  from tb_shop a left join tb_company b on a.company_id=b.id ";
    }

    public static  function GetCurtPurchaseID($companyId = null){
    	if($companyId == null){
    		$companyId = Users::GetLoginCommpanyID();
    	}
    	$filter = new SqlFilter("company_id",EQUALS,$companyId);
    	$filter ->addFilter("shop_type",EQUALS,PURCHASE);
    	$bean = AbstractBean::loadBean("Shop");
    	$bean ->loadFirst($filter);
    	return $bean->get("id");
    }

    public static  function GetCurtDCID($companyId = null){
    	if($companyId == null){
    		$companyId = Users::GetLoginCommpanyID();
    	}
    	$filter = new SqlFilter("company_id",EQUALS,$companyId);
    	$filter ->addFilter("shop_type",EQUALS,DC);
    	$bean = AbstractBean::loadBean("Shop");
    	$bean ->loadFirst($filter);
    	return $bean->get("id");
    }

     public static  function batchUpdateCompanyID(){
		AbstractBean::executeSql("update tb_shop set company_id = (select top 1 id from tb_company where tb_company.name = tb_shop.company_name ) where company_id is null");
     }

  
}
?>